package 每日一题;

public class 山峰数组的顶部 {

    public int peakIndexInMountainArray1(int[] arr) {
        int i=0;
        int j=arr.length-1;
        while (i<j){
            int mid = (i+j+1)/2;
            if (arr[mid-1]<arr[mid])
                i=mid;
            else
                j=mid-1;
        }
        return i;
    }

    public int peakIndexInMountainArray(int[] arr) {
        for (int i = 1; i < arr.length-1; i++) {
            if (arr[i]>arr[i-1] &&arr[i]>arr[i+1])
                return arr[i];
        }
        return -1;
    }
}
